<?php

class LoginController extends BaseController
{
    public function init()
    {
        $this->_helper->layout()->disableLayout();
    }


    public function indexAction()
    {
        $user_session = new Zend_Session_Namespace('login');
        if ($user_session->is_login) {
            $this->_redirect('/');
        }else{
            $req = $this->getRequest();
            if ($req->isPost()) {
                $account = $req->getPost('account');
                $pwd = $req->getPost('password');
                if ($account == '') {
                    $this->view->info = "请输入您的账号！";
                    return;
                }
                if ($pwd == '') {
                    $this->view->info = "请输入密码！";
                    return;
                }

                $staff = new \Biz\Staff();
                $re = $staff->login($account);
                if(!empty($re)){
                    $loginInfo = new Zend_Session_Namespace('login');
                    $loginInfo->user_id = $re['id'];
                    $loginInfo->account = $re['account'];
                    $loginInfo->pwd = $re['pwd'];
                    if(md5($pwd) == $re['pwd']){
                        $loginInfo->is_login  = true;
                        $this->_redirect("/index");
                    }else{
                        $this->view->info = "用户名与密码不匹配！";
                        return;
                    }
                }else{
                    $this->view->info = "账号不存在！";
                }
            }
        }
    }

    public function outAction()
    {
        Zend_Session::destroy();
        $this->_redirect('/');
    }
}